package com.hxh.crud.util;

import lombok.Data;

/**
 * @CreatedBy: hxh
 * @Date: 2020/2/22 16:52
 * @Description: 通用返回
 * @TODO: 加油吧！骚年！
 */
@Data
public class CommonResponse {

    // 状态码：200：成功、300：失败
    private int code;

    // 提示信息
    private String msg;

    // 返回的数据
    private Object data;


    // 成功方法
    public static CommonResponse success(String msg) {
        CommonResponse commonResponse = new CommonResponse();
        commonResponse.setCode(200);
        commonResponse.setMsg(msg);
        return commonResponse;
    }

    public static CommonResponse success(String msg, Object data) {
        CommonResponse commonResponse = new CommonResponse();
        commonResponse.setCode(200);
        commonResponse.setMsg(msg);
        commonResponse.setData(data);
        return commonResponse;
    }

    // 失败方法
    public static CommonResponse failure(String msg) {
        CommonResponse commonResponse = new CommonResponse();
        commonResponse.setCode(300);
        commonResponse.setMsg(msg);
        return commonResponse;
    }

    public static CommonResponse failure(String msg, Object data) {
        CommonResponse commonResponse = new CommonResponse();
        commonResponse.setCode(300);
        commonResponse.setMsg(msg);
        commonResponse.setData(data);
        return commonResponse;
    }

}
